1. Field of the Invention
The invention relates in general to a function-based software comparison method, and more particularly, to a software comparison method for software having the same functionality but different binary content.
2. Description of the Related Art
A modernized smart electronic device, e.g., a portable computer, a smart phone and various consumer electronic products, must be equipped with a processor. The processor executes software and/or firmware programs for implementing diversified functions of the electronic device. The programs can be easily modified, augmented or updated to improve, reinforce or enhancing functions of the electronic device.
In a software program, source code written in a high-level programming language is compiled into an object file by a compiler, and the object file is then connected to a library and converted to an executable file. A program usually includes one or more subroutines, each including one or more instructions. Different instructions correspond to different instruction functions. An object file or an executable file includes many machine codes, which represent the instructions of the program in a binary form. An electronic device allocates a certain storage space for successively storing machine codes of a same program section. A processor accesses the machine codes from the storage space and executes the machine codes to perform functions of the electronic device.
Due to complex functionality of modernized electronic devices, programs performed thereupon also become correspondingly complex. To correctly track modifications, revisions, upgrades, updates and tests of the programs, comparison of the programs is required.
A program comparison method of the prior art directly compares source code of two programs. It is clear that such a prior art approach has an obvious limit due to structural differences of original source code and syntax parsing differences of high-level programming languages. For example, users/test personnel cannot obtain a correct comparisons result through the above prior art approach if composers or the source code and users/test personnel of executable files are of different manufacturers.
Another comparison method of another prior art approach compares binary contents of object files or executable files of two programs. That is to say, when comparing the executable files of the two programs, the prior art sequentially compares bits or bytes of the machine codes in the object files or executable files. However, such an approach can only compare the binary contents of the programs but is incapable of identifying whether the two programs are identical (equivalent) in functionality. In many circumstances, two programs having different binary contents may be equivalent in functionality. For example, executable files compiled from the same source code by a compiler with different optimization settings, although being identical in functionality, may differ in contents.
Moreover, different program section settings may also result in different binary contents for two equivalent executable files. For example, if a plurality of functions of one executable file are allocated to a same program section and the same functions of another executable file are respectively allocated to two program sections, the two executable files will also have different binary contents while again being equivalent in functionality.
In addition, when functions of one executable file are modified, machine codes of neighboring functions may also be affected by incurring additional differences in the binary contents of the modified executable file. Thus, the above prior art may misjudge a modification range/level of the program.
In some cases, machine codes generated from compiling certain instructions are different but logically render same execution results. For example, two instructions “mov a0” (changing a variable a to a value 0) and “sub a a” (subtracting a variable a from a value of the variable a) have different formats but render the same results. In different compilers, a no-operation instruction may be compiled as “A=A”. If two programs contain these instructions, the above prior art based on the binary content comparison may likely determine that the two programs are different even when the execution results of the two programs are the same.